﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using QuanLyTruong.Business;
using System.Xml;
using System.IO;

namespace QuanLyTruong
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Truoc khi khoi tao form, thuc hien kiem tra pm da duoc kich hoat chua
            try
            {
                if (File.Exists(Application.StartupPath + "\\config.xml"))
                {
                    XmlDocument xd = new XmlDocument();
                    xd.Load(Application.StartupPath + "\\config.xml");

                    XmlNode xNode = xd.SelectSingleNode("connection/CDKey");
                    if (xNode != null)
                    {
                        string makhoitao = General.GenerateMakhoitao(xNode.InnerText);
                        string makichhoat = General.GenerateActiveNumber(makhoitao, xNode.InnerText);

                        XmlNode xMakichhoat = xd.SelectSingleNode("connection/ActiveNumber");
                        if (xMakichhoat != null)
                        {
                            string storedMakichhoat = xMakichhoat.InnerText;
                            if (makichhoat.ToLower().Trim() == storedMakichhoat.ToLower().Trim())
                            {
                                Application.Run(new frmLogin());
                            }
                            else
                            {
                                Application.Run(new frmDangkybanquyen());
                            }
                        }
                        else
                            Application.Run(new frmDangkybanquyen());
                    }
                    else
                        Application.Run(new frmDangkybanquyen());
                }
                else
                    Application.Run(new frmDangkybanquyen());
            }
            catch (Exception ex) { Application.Run(new frmDangkybanquyen()); }
            
        }
    }
}
